package net.begincode;

import com.google.common.collect.Lists;
import net.begincode.bean.HomeTypeWithBlogInfo;
import net.begincode.biz.HomeBiz;
import net.begincode.common.CollectionUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;

@Controller
@RequestMapping("/begincode/")
public class HomeController {

    @Resource
    private HomeBiz homeBiz;

    @RequestMapping(value = "")
    private ModelAndView home(){
        ModelAndView modelAndView = new ModelAndView();
        List<HomeTypeWithBlogInfo> homeTypeWithBlogInfoList = homeBiz.queryHomeInfo();
        homeTypeWithBlogInfoList.sort(Comparator.comparingInt(HomeTypeWithBlogInfo::getPriority));
        modelAndView.addObject("homeInfos",homeTypeWithBlogInfoList);
        modelAndView.setViewName("index");
        return modelAndView;
    }
}
